import axios from 'axios'
import { onRequest, onResponse, onRequestRejected, onResponseRejected } from './interceptors'

let instance = null
const useHttpInstance = () => {
  if (!instance) {
    instance = axios.create({
      baseURL: import.meta.env.VITE_API_BASE_URL
    })
    instance.interceptors.request.use(onRequest, onRequestRejected)
    instance.interceptors.response.use(onResponse, onResponseRejected)
  }
  return instance
}

export default useHttpInstance
